package com.jay.net.clazz.socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class ConnectionHandler implements Runnable {
	private Socket socket;
	
	public ConnectionHandler() {
	}
	public ConnectionHandler(Socket socket) {
		this.socket = socket;
	}

	public void run() {
		handleConversation(socket);
	}

	/**
	 * @param socket
	 *            Socket: must be closed on exit
	 */
	public void handleConversation(Socket socket) {
		try {
			InputStream in = socket.getInputStream();
			// read request from the input:
			// conversation not shown …
			OutputStream out = socket.getOutputStream();
			// write reply to the output
			out.flush();
		} catch (IOException e) { /* … */
		} finally {
			try {
				socket.close();
			} catch (IOException e) {
			}
		} // end finally
	} // end run()

	public Runnable setSocket(Socket socket) {
		this.socket = socket;
		return this;
	}
} // end class
